package com.iot.manage.dao;

import com.alibaba.fastjson.JSONObject;
import com.iot.manage.pojo.Menus;
import com.iot.manage.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface LoginMapper {
    @Select("<script>" +
            "SELECT\n" +
            "a.ID id,\n" +
            "a.PATH path,\n" +
            "a.AUTH_NAME authName,\n" +
            "a.ICON icon\n" +
            "FROM T_MENUS a WHERE a.PARENT_ID IS NULL AND a.HIDDEN = 0 ORDER BY a.ID" +
            "</script>")
    List<Menus> findRootMenus();

    @Select("<script>" +
            "SELECT\n" +
            "a.ID id,\n" +
            "a.PATH path,\n" +
            "a.AUTH_NAME authName,\n" +
            "a.ICON icon\n" +
            "FROM T_MENUS a WHERE a.PARENT_ID = #{parentId} AND a.HIDDEN = 0 ORDER BY a.ID" +
            "</script>")
    List<Menus> findChildMenus(@Param("parentId") int parentId);

    @Select("<script>" +
            "SELECT \n" +
            "\ta.USER_ID userId,\n" +
            "\ta.LOGIN_NAME loginName,\n" +
            "\ta.LOGIN_PASS loginPass,\n" +
            "\ta.USER_ACCESS userAccess\n" +
            "FROM T_USER a WHERE a.LOGIN_NAME = #{username}" +
            "</script>")
    List<User> findUserByName(JSONObject params);

    @Select("<script>" +
            "SELECT \n" +
            "\ta.LOGIN_PASS loginPass\n" +
            "FROM T_USER a WHERE a.LOGIN_NAME = #{username}" +
            "</script>")
    String findPassByName(JSONObject params);
}
